/*移动端返回事件处理*/
function judgeOnBack() {
    return 1; //1回到工作台
}
$(function () {
    //负责人
    var addressLocation='';
    var deptArr='';  //存放所有部门列表
    /*部门列表*/
    var isDept='';  //部门是否改变
    function dept() {
        var url='/test/mode/list/dept';
        var mdObj=md5Fun(appUserId,url,appToken);
        $.ajax({
            type: "POST",
            timeout : 5000,
            url: webUrlCon+url,
            beforeSend: function(request) {
                request.setRequestHeader("Content-Type", "application/json");
                request.setRequestHeader("sequence", mdObj.sequence);
                request.setRequestHeader("nonceStr", mdObj.nonceStr);
                request.setRequestHeader("userId", appUserId);
                request.setRequestHeader("token",appToken);
                //xmlhttp.setRequestHeader("infName", url);
                //xmlhttp.setRequestHeader("osVersion", '');
                request.setRequestHeader("versionType", "1");
                request.setRequestHeader("osPlatform", mdObj.osPlatform);
                request.setRequestHeader("appVersion", mdObj.appVersion);
                request.setRequestHeader("sign", mdObj.sign);
            },
            success: function (data) {
                //console.log('/test/mode/list/dept');
                //console.log(data);
                if(data.code==100) {
                    deptArr=Decrypt(data.content);
                    deptArr=JSON.parse(deptArr);
                    //console.log(deptArr);
                    /* 部门组别 */
                    var groupArr=[{'id':0,'value':'无'}];
                    var url='/test/mode/list/group';
                    var mdObj=md5Fun(appUserId,url,appToken);
                    var parameterObj= {
                        "deptId":deptArr[0].id
                    };
                    var parameter=Encrypt(JSON.stringify(parameterObj));
                    //console.log(parameter)
                    //console.log(Decrypt(parameter));
                    $.ajax({
                        type: "POST",
                        timeout : 5000,
                        url: webUrlCon+url,
                        data:JSON.stringify(
                            {"parameter":parameter}
                        ),
                        beforeSend: function(request) {
                            request.setRequestHeader("Content-Type", "application/json");
                            request.setRequestHeader("sequence", mdObj.sequence);
                            request.setRequestHeader("nonceStr", mdObj.nonceStr);
                            request.setRequestHeader("userId", appUserId);
                            request.setRequestHeader("token",appToken);
                            //xmlhttp.setRequestHeader("infName", url);
                            //xmlhttp.setRequestHeader("osVersion", '');
                            request.setRequestHeader("versionType", "1");
                            request.setRequestHeader("osPlatform", mdObj.osPlatform);
                            request.setRequestHeader("appVersion", mdObj.appVersion);
                            request.setRequestHeader("sign", mdObj.sign);
                        },
                        success: function (data) {
                            //console.log('/test/mode/list/group');
                            //console.log(data);
                            if(data.code==100) {
                                var groupArrObj=Decrypt(data.content);
                                groupArrObj=JSON.parse(groupArrObj);
                                //console.log(groupArrObj);
                                if(groupArrObj.length>0){
                                    groupArr=groupArrObj
                                }
                                /* 部门组别人员 */
                                var personnelArr=[{'id':0,'value':'无'}];
                                var url='/test/mode/list/user';
                                var mdObj=md5Fun(appUserId,url,appToken);
                                var parameterObj= {
                                    "groupId":groupArr[0].id
                                };
                                var parameter=Encrypt(JSON.stringify(parameterObj));
                                //console.log(parameter)
                                //console.log(Decrypt(parameter));
                                $.ajax({
                                    type: "POST",
                                    timeout : 5000,
                                    url: webUrlCon+url,
                                    data:JSON.stringify(
                                        {"parameter":parameter}
                                    ),
                                    beforeSend: function(request) {
                                        request.setRequestHeader("Content-Type", "application/json");
                                        request.setRequestHeader("sequence", mdObj.sequence);
                                        request.setRequestHeader("nonceStr", mdObj.nonceStr);
                                        request.setRequestHeader("userId", appUserId);
                                        request.setRequestHeader("token",appToken);
                                        //xmlhttp.setRequestHeader("infName", url);
                                        //xmlhttp.setRequestHeader("osVersion", '');
                                        request.setRequestHeader("versionType", "1");
                                        request.setRequestHeader("osPlatform", mdObj.osPlatform);
                                        request.setRequestHeader("appVersion", mdObj.appVersion);
                                        request.setRequestHeader("sign", mdObj.sign);
                                    },
                                    success: function (data) {
                                        //console.log('/test/mode/list/group');
                                        //console.log(data);
                                        if(data.code==100) {
                                            var personnelArrObj=Decrypt(data.content);
                                            personnelArrObj=JSON.parse(personnelArrObj);
                                            //console.log(groupArrObj);
                                            if(personnelArrObj.length>0){
                                                personnelArr=personnelArrObj
                                            }
                                            addressLocation= new MobileSelect({
                                                trigger: '#personName',
                                                title: '负责人',
                                                wheels: [
                                                    {data:deptArr},
                                                    {data:groupArr},
                                                    {data:personnelArr}
                                                ],
                                                triggerDisplayData:false,
                                                position:[0,0,0],
                                                callback:function(indexArr, data){
                                                    if(data[2].id!=0){
                                                        $('#personLiable').attr('user',data[2].id);
                                                    }else {
                                                        $('#personLiable').attr('user','');
                                                    }
                                                    $('#personLiable').val(data[2].value);
                                                },
                                                transitionEnd:function(indexArr, data){
                                                    //console.log('isDeptId='+isDeptId+' isGroup='+isGroup);
                                                    //console.log(data)
                                                    //console.log('data[0].id='+data[0].id+' data[1].id='+data[1].id)
                                                    //group(data[0].id);
                                                    if(isDeptId!=data[0].id){
                                                        group(data[0].id);
                                                    }else if(isGroup!=data[1].id){
                                                        personnel(data[1].id);
                                                    }
                                                    //console.log(indexArr); //
                                                    //console.log(data); //返回选中的json数据
                                                    // group(data[0].id);
                                                }
                                            });
                                            //console.log(addressLocation.getValue())
                                            isDeptId=addressLocation.getValue()[0].id;
                                            isGroup=addressLocation.getValue()[0].id;
                                        }
                                    }
                                });
                            }
                        }
                    });
                }
            },
            error: function(e) {

            }
        });
    }

    /*部门组别列表*/
    var isDeptId='';  //是否请求部门组别数据
    function group(deptId) {
        var url='/test/mode/list/group';
        var mdObj=md5Fun(appUserId,url,appToken);
        var parameterObj= {
            "deptId":deptId
        };
        var parameter=Encrypt(JSON.stringify(parameterObj));
        if(isDeptId!=deptId){
            $.ajax({
                type: "POST",
                timeout : 5000,
                url: webUrlCon+url,
                data:JSON.stringify(
                    {"parameter":parameter}
                ),
                beforeSend: function(request) {
                    request.setRequestHeader("Content-Type", "application/json");
                    request.setRequestHeader("sequence", mdObj.sequence);
                    request.setRequestHeader("nonceStr", mdObj.nonceStr);
                    request.setRequestHeader("userId", appUserId);
                    request.setRequestHeader("token",appToken);
                    //xmlhttp.setRequestHeader("infName", url);
                    //xmlhttp.setRequestHeader("osVersion", '');
                    request.setRequestHeader("versionType", "1");
                    request.setRequestHeader("osPlatform", mdObj.osPlatform);
                    request.setRequestHeader("appVersion", mdObj.appVersion);
                    request.setRequestHeader("sign", mdObj.sign);
                },
                success: function (data) {
                    //console.log('/test/mode/list/groupArrgroupArrgroupArrgroupArr');
                    //console.log(data);
                    if(data.code==100) {
                        var groupArr=Decrypt(data.content);
                        groupArr=JSON.parse(groupArr);
                        //console.log(groupArr);
                        if(groupArr.length==0){
                            groupArr.push({'id':0,'value':'无'})
                        }
                        addressLocation.updateWheel(1,groupArr);
                        addressLocation.locatePostion(1,0);
                        personnel(groupArr[0].id);
                    }
                },
            });
        }
        isDeptId=deptId;
    }
    /*部门组人员列表*/
    var isGroup='';  //是否请求部门组别人员数据
    function personnel(groupId) {
        var url='/test/mode/list/user';
        var mdObj=md5Fun(appUserId,url,appToken);
        var parameterObj= {
            "groupId":groupId
        };
        var parameter=Encrypt(JSON.stringify(parameterObj));
        if(isGroup!=groupId){
            $.ajax({
                type: "POST",
                timeout : 5000,
                url: webUrlCon+url,
                data:JSON.stringify(
                    {"parameter":parameter}
                ),
                beforeSend: function(request) {
                    request.setRequestHeader("Content-Type", "application/json");
                    request.setRequestHeader("sequence", mdObj.sequence);
                    request.setRequestHeader("nonceStr", mdObj.nonceStr);
                    request.setRequestHeader("userId", appUserId);
                    request.setRequestHeader("token",appToken);
                    //xmlhttp.setRequestHeader("infName", url);
                    //xmlhttp.setRequestHeader("osVersion", '');
                    request.setRequestHeader("versionType", "1");
                    request.setRequestHeader("osPlatform", mdObj.osPlatform);
                    request.setRequestHeader("appVersion", mdObj.appVersion);
                    request.setRequestHeader("sign", mdObj.sign);
                },
                success: function (data) {
                    //console.log('/test/mode/list/groupArrgroupArrgroupArrgroupArr');
                    //console.log(data);
                    if(data.code==100) {
                        var personnelArr=Decrypt(data.content);
                        personnelArr=JSON.parse(personnelArr);
                        //console.log(groupArr);
                        if(personnelArr.length==0){
                            personnelArr.push({'id':0,'value':'无'})
                        }
                        addressLocation.updateWheel(2,personnelArr);
                        addressLocation.locatePostion(2,0);
                        isDeptId=addressLocation.getValue()[0].id;
                        isGroup=addressLocation.getValue()[1].id;
                    }
                },
            });
        }
        isGroup=groupId;
    }

    var partType=3;  //零件类型（2：注塑 3：金属 4: 装备制造）
    var qualityProcessId =0;  //质检工序ID（4: 装备制造）


    var partCode='100331211W'; //金属
    //var partCode='002021213Z'; //注塑


    if (u.indexOf('iPhone') > -1) {   //苹果手机
        setTimeout(function () {
            WebViewJavascriptBridge.callHandler('setRight', {'text': '历史质检','url':'qualityHistory.html'}, function(response) {

            })
            WebViewJavascriptBridge.callHandler('getPartCode', {'foo': 'bar'}, function(response) {
               /*layer.open({
                    content: response
                    ,btn: '确定'
                });*/
                response=JSON.parse(response);
                appToken=response.token;
                appUserId=response.userId;
                localStorage.appToken=appToken;
                localStorage.appUserId=appUserId;
                sessionStorage.reworkProcedure=JSON.stringify(JSON.parse(response.partCode).reworkProcedure);
                qualityProcessId=response.qualityProcessId; //质检工序ID
                dept();
                qualitModeHmtl(response.partCode);

            })
        },50);
    }else {
        jsObj.setRight('历史质检','qualityHistory.html');
        var response=jsObj.getPartCode();
        //alert(response)
        response=JSON.parse(response);
        appToken=response.token;
        appUserId=response.userId;
        localStorage.appToken=appToken;
        localStorage.appUserId=appUserId;
        sessionStorage.reworkProcedure=JSON.stringify(JSON.parse(response.partCode).reworkProcedure);
        //alert(JSON.stringify(JSON.parse(response.partCode).reworkProcedure));
        qualityProcessId=response.qualityProcessId; //质检工序ID
        dept()
        qualitModeHmtl(response.partCode)


    }
    /* OSS*/
    //send_request();

    /*扫码进入质检*/
    //qualitMode()
    //dept()
    function qualitMode() {
        var url='/mes/zw/quality/enter/quality';
        var mdObj=md5Fun(appUserId,url,appToken);
        var parameterObj= {
            "partCode":partCode,
            "type":partType
        };
        var parameter=Encrypt(JSON.stringify(parameterObj));
        //console.log(parameter)
        console.log(Decrypt(parameter));
        $.ajax({
            type: "POST",
            timeout : 5000,
            url: webUrlCon+url,
            data:JSON.stringify(
                {"parameter":parameter}
            ),
            beforeSend: function(request) {
                request.setRequestHeader("Content-Type", "application/json");
                request.setRequestHeader("sequence", mdObj.sequence);
                request.setRequestHeader("nonceStr", mdObj.nonceStr);
                request.setRequestHeader("userId", appUserId);
                request.setRequestHeader("token",appToken);
                //xmlhttp.setRequestHeader("infName", url);
                //xmlhttp.setRequestHeader("osVersion", '');
                request.setRequestHeader("versionType", "1");
                request.setRequestHeader("osPlatform", mdObj.osPlatform);
                request.setRequestHeader("appVersion", mdObj.appVersion);
                request.setRequestHeader("sign", mdObj.sign);
            },
            success: function (data) {
                //console.log(data);
                if(data.code==100){
                    var qualityModeList=Decrypt(data.content);
                    qualitModeHmtl(qualityModeList)
                }else if(data.code==102){
                    //没有找到该零件监控编号的信息
                    layer.open({
                        content: data.message
                        ,btn: '确定'
                    });
                }else{
                    layer.open({
                        content: data.code+' '+data.message
                        ,btn: '确定'
                    });
                }
            },
            error: function(e) {
                layer.open({
                    content: '无法请求服务器，请稍后再试！'
                    ,btn: '确定'
                });
            }
        });
    }

    //生成html
    function qualitModeHmtl(qualityModeList) {
        var content=JSON.parse(qualityModeList);
        partType=content.partType;  //零件类型 1 模具 2 注塑 3金属 4 装备制造
        sessionStorage.partType=partType;
        $('.startQualityBox').attr('part-detail-id',content.partDetailId);  //零件详情ID
        if(partType==4){
            $('.startQualityBox .title').html('产品监控编号：'+content.partmCode);
            $('.productCode').html('产品编号：'+content.productCode);
            $('.productOrderNum').html('生产单数量：'+content.productOrderNum);
            $('.finishNum').html('已完成数量：'+content.finishNum);
            $('.surplusNum').html('剩余数量：'+(content.productOrderNum-content.finishNum));

            $('.partName').hide();
            $('.partmCode').hide();
        }else {
            $('.startQualityBox .title').html('零件编号：'+content.partCode);
            $('.partName').html('零件名称：'+content.partName);
            $('.partmCode').html('零件监控编号：'+content.partmCode);
            $('.productOrderNum').hide();
            $('.finishNum').hide();
            $('.surplusNum').hide();
            $('.productCode').hide();
        }
        $('.productionCode').html('生产单号：'+content.productionCode);
        $('.productName').html('产品名称：'+content.productName);
        if(content.status==1){    // 1 正在质检
            $('.startQualityBox').attr('quality-id',content.qualityID); //质检ID

            var qualityHtml='<p><span>质检名称：</span>'+content.qualityName+'</p>' +
                '<p><span>质检内容：</span>'+content.qualityContent+'</p>' +
                '<p><span>计划工时：</span>'+content.planHours+'小时</p>' +
                '<p><span>开始时间：</span>'+formatDateTime(content.startDate)+'</p>' +
                '<p><span>已质检数量：</span>'+content.qualityCountTotal+'</p>' +
                '<p><span>已质检不合格数量：</span>'+content.unqualityCountTotal+'</p>';
            localStorage.qualityCountTotal=content.qualityCountTotal;  //已质检数量
            localStorage.unqualityCountTotal=content.unqualityCountTotal;  //已质检不合格数量
            localStorage.qualityType=content.qualityType==undefined?'':content.qualityType;  //质检类型 1 PQC首件 2 巡检 3终检
            if(content.inspectFrequency!=undefined){
                qualityHtml+='<p><span>巡检频度：</span>'+content.inspectFrequency+'</p>';
            }
            /*if(content.sufficeRate!=undefined){
                qualityHtml+='<p><span>良品率：</span>'+content.sufficeRate+'%</p>';
            }*/
            $('.qualityContentInfo').html(qualityHtml);
            $('.startQualityBox').removeClass('startQuality');
        }else if(content.status==2){  //质检完成
            /*layer.open({
                content: '该零件监控编号已完质检，跳转到历史质检页面'
                ,btn: '确定'
                ,shadeClose:false
                , yes: function(index){
                    layer.close(index)
                    //location.href='testHistory.html';
                }
            });*/
        }
        $('.main').show();
        $('.spinner').hide();
    }


    $('body').on('click','.layuiClose',function () {
        layer.closeAll();
    });
    //开始质检
    $('.main').on('click','.start',function () {
        if(partType==4){  //装备制造
            layer.open({
                content: '是否开始质检'
                ,btn: ['确定', '取消']
                ,shadeClose:false
                ,yes: function(index){
                    layer.closeAll();
                    //开始质检
                    var url='/mes/assembl/make/start/quality';
                    var mdObj=md5Fun(appUserId,url,appToken);
                    var parameterObj= {
                        "partDetailId":$('.startQualityBox').attr('part-detail-id'),
                        "qualityProcessId":qualityProcessId
                    };
                    var parameter=Encrypt(JSON.stringify(parameterObj));
                    console.log(parameter)
                    console.log(Decrypt(parameter));
                    $.ajax({
                        type: "POST",
                        timeout : 5000,
                        url: webUrlCon+url,
                        data:JSON.stringify(
                            {"parameter":parameter}
                        ),
                        beforeSend: function(request) {
                            request.setRequestHeader("Content-Type", "application/json");
                            request.setRequestHeader("sequence", mdObj.sequence);
                            request.setRequestHeader("nonceStr", mdObj.nonceStr);
                            request.setRequestHeader("userId", appUserId);
                            request.setRequestHeader("token",appToken);
                            //xmlhttp.setRequestHeader("infName", url);
                            //xmlhttp.setRequestHeader("osVersion", '');
                            request.setRequestHeader("versionType", "1");
                            request.setRequestHeader("osPlatform", mdObj.osPlatform);
                            request.setRequestHeader("appVersion", mdObj.appVersion);
                            request.setRequestHeader("sign", mdObj.sign);
                        },
                        success: function (data) {
                            //console.log(data);
                            if(data.code==100){
                                content=Decrypt(data.content);
                                content=JSON.parse(content);
                                console.log(content);
                                partType=content.partType;  //零件类型 1 模具 2 注塑 3金属 4 装备制造
                                $('.startQualityBox').attr('quality-id',content.qualityID); //质检ID
                                var qualityHtml='<p><span>质检名称：</span>'+content.qualityName+'</p>' +
                                    '<p><span>质检内容：</span>'+content.qualityContent+'</p>' +
                                    '<p><span>计划工时：</span>'+content.planHours+'小时</p>' +
                                    '<p><span>开始时间：</span>'+formatDateTime(content.startDate)+'</p>' +
                                    '<p><span>已质检数量：</span>'+content.qualityCountTotal+'</p>' +
                                    '<p><span>已质检不合格数量：</span>'+content.unqualityCountTotal+'</p>';
                                localStorage.qualityCountTotal=content.qualityCountTotal;  //已质检数量
                                localStorage.unqualityCountTotal=content.unqualityCountTotal;  //已质检不合格数量
                                localStorage.qualityType=content.qualityType==undefined?'':content.qualityType;  //质检类型 1 PQC首件 2 巡检 3终检
                                if(content.inspectFrequency!=undefined){
                                    qualityHtml+='<p><span>巡检频度：</span>'+content.inspectFrequency+'</p>';
                                }
                                /*if(content.sufficeRate!=undefined){
                                    qualityHtml+='<p><span>良品率：</span>'+content.sufficeRate+'%</p>';
                                }*/
                                $('.qualityContentInfo').html(qualityHtml);
                                $('.startQualityBox').removeClass('startQuality');
                            }else{
                                layer.open({
                                    content: data.code+' '+data.message
                                    ,btn: '确定'
                                });
                            }
                        },
                        error: function(e) {
                            layer.open({
                                content: '无法请求服务器，请稍后再试！'
                                ,btn: '确定'
                            });
                        }
                    });
                }
            });
        }else {
            var url='/mes/zw/quality/select/quality';
            var mdObj=md5Fun(appUserId,url,appToken);
            var parameterObj= {
                "partDetailId":$('.startQualityBox').attr('part-detail-id')
            };
            var parameter=Encrypt(JSON.stringify(parameterObj));
            console.log(parameter);
            console.log(Decrypt(parameter));
            $.ajax({
                type: "POST",
                timeout : 5000,
                url: webUrlCon+url,
                data:JSON.stringify(
                    {"parameter":parameter}
                ),
                beforeSend: function(request) {
                    request.setRequestHeader("Content-Type", "application/json");
                    request.setRequestHeader("sequence", mdObj.sequence);
                    request.setRequestHeader("nonceStr", mdObj.nonceStr);
                    request.setRequestHeader("userId", appUserId);
                    request.setRequestHeader("token",appToken);
                    //xmlhttp.setRequestHeader("infName", url);
                    //xmlhttp.setRequestHeader("osVersion", '');
                    request.setRequestHeader("versionType", "1");
                    request.setRequestHeader("osPlatform", mdObj.osPlatform);
                    request.setRequestHeader("appVersion", mdObj.appVersion);
                    request.setRequestHeader("sign", mdObj.sign);
                },
                success: function (data) {
                    //console.log(data);
                    if(data.code==100){
                        content=Decrypt(data.content);
                        content=JSON.parse(content);
                        console.log(content);
                        if(content.length>0){
                            var str='<div class="title">选择质检类型<span class="but layuiClose">取消</span></div>';
                            str+='<div class="content layuiContent"><ul>';
                            for(var i=0;i<content.length;i++){
                                str+='<li quality-process-id="'+content[i].id+'">'+content[i].name+'</li>';
                            }
                            str+='</ul></div>';
                            layer.open({
                                type: 1
                                ,content: str
                                ,anim: 'up'
                                ,style: 'position:fixed; bottom:0; left:0; width: 100%; height: 200px; padding:10px 0; border:none;'
                            });
                        }else{
                            layer.open({
                                content: data.code+' 没有质检类型可选择'
                                ,btn: '确定'
                            });
                        }

                    }else{
                        layer.open({
                            content: data.code+' '+data.message
                            ,btn: '确定'
                        });
                    }
                },
                error: function(e) {
                    layer.open({
                        content: '无法请求服务器，请稍后再试！'
                        ,btn: '确定'
                    });
                }
            });
        }
    });
    //开始质检-选择质检类型
    $('body').on('click','.layuiContent ul li',function () {
        layer.closeAll();
        var _this=this;
        layer.open({
            content: '是否开始质检'
            ,btn: ['确定', '取消']
            ,shadeClose:false
            ,yes: function(index){
                layer.closeAll();
                //开始质检
                var url='/mes/zw/quality/start/quality';
                var mdObj=md5Fun(appUserId,url,appToken);
                var parameterObj= {
                    "partDetailId":$('.startQualityBox').attr('part-detail-id'),
                    "qualityProcessId":$(_this).attr('quality-process-id')
                };
                var parameter=Encrypt(JSON.stringify(parameterObj));
                console.log(parameter)
                console.log(Decrypt(parameter));
                $.ajax({
                    type: "POST",
                    timeout : 5000,
                    url: webUrlCon+url,
                    data:JSON.stringify(
                        {"parameter":parameter}
                    ),
                    beforeSend: function(request) {
                        request.setRequestHeader("Content-Type", "application/json");
                        request.setRequestHeader("sequence", mdObj.sequence);
                        request.setRequestHeader("nonceStr", mdObj.nonceStr);
                        request.setRequestHeader("userId", appUserId);
                        request.setRequestHeader("token",appToken);
                        //xmlhttp.setRequestHeader("infName", url);
                        //xmlhttp.setRequestHeader("osVersion", '');
                        request.setRequestHeader("versionType", "1");
                        request.setRequestHeader("osPlatform", mdObj.osPlatform);
                        request.setRequestHeader("appVersion", mdObj.appVersion);
                        request.setRequestHeader("sign", mdObj.sign);
                    },
                    success: function (data) {
                        //console.log(data);
                        if(data.code==100){
                            content=Decrypt(data.content);
                            content=JSON.parse(content);
                            console.log(content);
                            partType=content.partType;  //零件类型 1 模具 2 注塑 3金属 4 装备制造
                            $('.startQualityBox').attr('quality-id',content.qualityID); //质检ID
                            var qualityHtml='<p><span>质检名称：</span>'+content.qualityName+'</p>' +
                                '<p><span>质检内容：</span>'+content.qualityContent+'</p>' +
                                '<p><span>计划工时：</span>'+content.planHours+'小时</p>' +
                                '<p><span>开始时间：</span>'+formatDateTime(content.startDate)+'</p>' +
                                '<p><span>已质检数量：</span>'+content.qualityCountTotal+'</p>' +
                                '<p><span>已质检不合格数量：</span>'+content.unqualityCountTotal+'</p>';
                            localStorage.qualityCountTotal=content.qualityCountTotal;  //已质检数量
                            localStorage.unqualityCountTotal=content.unqualityCountTotal;  //已质检不合格数量
                            localStorage.qualityType=content.qualityType==undefined?'':content.qualityType;  //质检类型 1 PQC首件 2 巡检 3终检
                            if(content.inspectFrequency!=undefined){
                                qualityHtml+='<p><span>巡检频度：</span>'+content.inspectFrequency+'</p>';
                            }
                            /*if(content.sufficeRate!=undefined){
                                qualityHtml+='<p><span>良品率：</span>'+content.sufficeRate+'%</p>';
                            }*/
                            $('.qualityContentInfo').html(qualityHtml);
                            $('.startQualityBox').removeClass('startQuality');
                        }else{
                            layer.open({
                                content: data.code+' '+data.message
                                ,btn: '确定'
                            });
                        }
                    },
                    error: function(e) {
                        layer.open({
                            content: '无法请求服务器，请稍后再试！'
                            ,btn: '确定'
                        });
                    }
                });
            }
        });
    });

    //去掉 交班，完成质检提示红字
    $('body').on('blur','.conIntBox input',function () {
        $(this).parents('.conIntBox').removeClass('active');
    });
    //交班 shift
    $('.main').on('click','.bottomBut .shift',function () {
        var strTit=$(this).html();
        if(partType==4){strTit='是否交班'}
        var str='<div class="title" style="padding-bottom: 0.3rem;">'+strTit+'<i class="but layuiClose iconfont icon-guanbi"></i></div>';
        if(partType==4){  //装备制造

        }else if(partType==3){  //金属
            str+='<div class="conIntBox qualityCountTop"><span class="txt">数量</span><span class="conInt"><input id="qualityCount" type="number" placeholder="输入本次质检数量" onkeyup="this.value=this.value.replace(/\\D/g,\'\')" onafterpaste="this.value=this.value.replace(/\\D/g,\'\')"></span></div>';
            str+='<div class="conIntBox unqualityCountTop"><span class="txt">次品</span><span class="conInt"><input id="unqualityCount" type="number" placeholder="输入本次不合格数量" onkeyup="this.value=this.value.replace(/\\D/g,\'\')" onafterpaste="this.value=this.value.replace(/\\D/g,\'\')"></span></div>';
            str+='<div class="conIntBox batchTop"><span class="txt">批次</span><span class="conInt batch"><input id="batch" type="text" placeholder="输入零件批次号"><!--<i class="icon iconfont icon-saoma"></i>--></span></div>';
        }else if(partType==2){    //注塑
            str+='<div class="conIntBox qualityCountTop"><span class="txt">数量</span><span class="conInt"><input id="qualityCount" type="number" placeholder="输入本次质检数量" onkeyup="this.value=this.value.replace(/\\D/g,\'\')" onafterpaste="this.value=this.value.replace(/\\D/g,\'\')"></span></div>';
            str+='<div class="conIntBox unqualityCountTop"><span class="txt">次品</span><span class="conInt"><input id="unqualityCount" type="number" placeholder="输入本次不合格数量" onkeyup="this.value=this.value.replace(/\\D/g,\'\')" onafterpaste="this.value=this.value.replace(/\\D/g,\'\')"></span></div>';
            if(localStorage.qualityType!=1){
                str+='<div class="conIntBox batchTop"><span class="txt">批次</span><span class="conInt batch"><input id="batch" type="text" placeholder="输入零件批次号"><!--<i class="icon iconfont icon-saoma"></i>--></span></div>';
            }
        }
        if(partType==4){
            str+='<div class="qualityModeBut layuiClose" style="border-top-right-radius: 0; border-bottom-right-radius: 0; width: 50%; margin-right: 0;">取消</div><div class="qualityModeBut shiftBut active" style="border-top-left-radius: 0; border-bottom-left-radius: 0; width: 50%; margin-right: 0;">提交</div>';
        }else {
            str+='<div class="qualityModeBut shiftBut active">提交</div>';
        }
        layer.open({
            className: 'layui-select',
            zIndex:200,
            //shadeClose:false,
            content: str
        });
    });

    //交班-提交质检
    $('body').on('click','.shiftBut',function () {
        localStorage.qualityId=$('.startQualityBox').attr('quality-id');
        localStorage.qualityCount=$('#qualityCount').val();
        localStorage.unqualityCount=$('#unqualityCount').val();
        localStorage.batch=$('#batch').val();
        localStorage.img1='';
        localStorage.img2='';
        localStorage.img3='';
        localStorage.img4='';
        $('#testImages .img').each(function (index) {
            if(index==0){localStorage.img1=$(this).find('img').attr('data-url');}
            if(index==1){localStorage.img2=$(this).find('img').attr('data-url');}
            if(index==2){localStorage.img3=$(this).find('img').attr('data-url');}
            if(index==3){localStorage.img4=$(this).find('img').attr('data-url');}
        })
        if(partType==4){  //装备制造
            localStorage.qualType=1;  //1交班 2完成质检
            localStorage.qualityCount=0;
            localStorage.result=1;

            var shiftObj={
                qualityId:localStorage.qualityId,
                qualityCount:localStorage.qualityCount,
                result:localStorage.result,
                type:localStorage.qualType,
                img1:localStorage.img1,
                img2:localStorage.img2,
                img3:localStorage.img3,
                img4:localStorage.img4,
            }
            metail(shiftObj)

        }else if(partType==3){  //金属
            localStorage.qualType=1;  //1交班 2完成质检
            if(localStorage.qualityCount==""){
                $('.qualityCountTop').addClass('active');
            }else if(localStorage.unqualityCount==""){
                $('.unqualityCountTop').addClass('active');
            }else if(localStorage.batch==""){
                $('.batchTop').addClass('active');
            }else {
                if(parseInt(localStorage.unqualityCount)>0){
                    if (u.indexOf('iPhone') > -1) {   //苹果手机
                        location.href='qualityUnqual.html';
                    }else {
                        jsObj.openHyperLinkReference('qualityUnqual.html');
                    }
                }else{
                    var shiftObj={
                        qualityId:localStorage.qualityId,
                        qualityCount:localStorage.qualityCount,
                        unqualityCount:localStorage.unqualityCount,
                        batch:localStorage.batch,
                        type:localStorage.qualType,
                        img1:localStorage.img1,
                        img2:localStorage.img2,
                        img3:localStorage.img3,
                        img4:localStorage.img4,
                    }
                    metail(shiftObj)
                }
            }
        }else{  //注塑
            localStorage.qualType=1;  //1交班 2完成质检
            if(localStorage.qualityCount==""){
                $('.qualityCountTop').addClass('active');
            }else if(localStorage.unqualityCount==""){
                $('.unqualityCountTop').addClass('active');
            }else if(localStorage.qualityType!=1&&localStorage.batch==""){   //只有 2 巡检 3终检
                $('.batchTop').addClass('active');
            }else {
                var shiftObj={
                    qualityId:localStorage.qualityId,
                    qualityCount:localStorage.qualityCount,
                    unqualityCount:localStorage.unqualityCount,
                    batch:localStorage.batch,
                    type:localStorage.qualType,
                    img1:localStorage.img1,
                    img2:localStorage.img2,
                    img3:localStorage.img3,
                    img4:localStorage.img4,
                }
                plastic(shiftObj)
            }
        }
    });
    //选择质检结果 isQuality
    $('body').on('click','.isQuality',function () {
        $('.isQualityTop').removeClass('active');
        $('.isQuality').removeClass('active');
        $(this).addClass('active');
        if(partType==2){  //注塑
            if($(this).hasClass('no')){ //1 合格（通过） 2 不合格（异常）
                //localStorage.result=2
                $('.isAbnormalTop').show();
                $('.personLiable').show();
            }else{
                //localStorage.result=1
                $('.isAbnormalTop').hide();
                $('.personLiable').hide();
            }
        }
    });
    //异常零件处理 isAbnormal
    $('body').on('click','.isAbnormal',function () {
        $('.isAbnormalTop').removeClass('active');
        $('.isAbnormal').removeClass('active');
        $(this).addClass('active');
    });
    //完成质检 adopt
    $('.main').on('click','.bottomBut .adopt',function () {
        var str='<div class="title" style="padding-bottom: 0.3rem;">'+$(this).html()+'<i class="but layuiClose iconfont icon-guanbi"></i></div>';
        if(partType==4){  //装备制造
            str+='<div class="conIntBox isQualityTop"><span class="txt">质检结果</span><span class="isQuality no"><i class="icon iconfont icon-jinyong1"></i>异常</span><span class="isQuality yes"><i class="icon iconfont icon-jinyong1"></i>通过</span></div>';
        }else if(partType==3){  //金属
            str+='<div class="conIntBox qualityCountTop"><span class="txt">数量</span><span class="conInt"><input id="qualityCount" type="number" placeholder="输入本次质检数量" onkeyup="this.value=this.value.replace(/\\D/g,\'\')" onafterpaste="this.value=this.value.replace(/\\D/g,\'\')"></span></div>';
            str+='<div class="conIntBox unqualityCountTop"><span class="txt">次品</span><span class="conInt"><input id="unqualityCount" type="number" placeholder="输入本次不合格数量" onkeyup="this.value=this.value.replace(/\\D/g,\'\')" onafterpaste="this.value=this.value.replace(/\\D/g,\'\')"></span></div>';
            str+='<div class="conIntBox batchTop"><span class="txt">批次</span><span class="conInt batch"><input id="batch" type="text" placeholder="输入零件批次号"><!--<i class="icon iconfont icon-saoma"></i>--></span></div>';
            str+='<div class="conIntBox isQualityTop"><span class="txt">质检结果</span><span class="isQuality no"><i class="icon iconfont icon-jinyong1"></i>异常</span><span class="isQuality yes"><i class="icon iconfont icon-jinyong1"></i>通过</span></div>';
            str+='<div class="conIntBox sunNum"><span class="txt">总质检数量：</span><span class="num">'+localStorage.qualityCountTotal+'</span></div>';
            str+='<div class="conIntBox noNum"><span class="txt">总不合格数量：</span><span class="num">'+localStorage.unqualityCountTotal+'</span></div>';
        }else if(partType==2){    //注塑
            str+='<div class="conIntBox qualityCountTop"><span class="txt">数量</span><span class="conInt"><input id="qualityCount" type="number" placeholder="输入本次质检数量" onkeyup="this.value=this.value.replace(/\\D/g,\'\')" onafterpaste="this.value=this.value.replace(/\\D/g,\'\')"></span></div>';
            str+='<div class="conIntBox unqualityCountTop"><span class="txt">次品</span><span class="conInt"><input id="unqualityCount" type="number" placeholder="输入本次不合格数量" onkeyup="this.value=this.value.replace(/\\D/g,\'\')" onafterpaste="this.value=this.value.replace(/\\D/g,\'\')"></span></div>';
            if(localStorage.qualityType!=1){
                str+='<div class="conIntBox batchTop"><span class="txt">批次</span><span class="conInt batch"><input id="batch" type="text" placeholder="输入零件批次号"><!--<i class="icon iconfont icon-saoma"></i>--></span></div>';
            }
            str+='<div class="conIntBox isQualityTop"><span class="txt">质检结果</span><span class="isQuality no"><i class="icon iconfont icon-jinyong1"></i>异常</span><span class="isQuality yes"><i class="icon iconfont icon-jinyong1"></i>通过</span></div>';
            str+='<div class="conIntBox isAbnormalTop"><span class="txt">异常零件处理</span><span class="isAbnormal no"><i class="icon iconfont icon-jinyong1"></i>废弃</span><span class="isAbnormal yes"><i class="icon iconfont icon-jinyong1"></i>返工</span></div>';
            str+='<div class="conIntBox personLiable"><span class="txt">责任人</span><span class="conInt personLiableSel" id="group"><input id="personLiable" readonly unselectable="on" onfocus="this.blur()"  class="group"  placeholder="请选择负责人"><i class="groupI icon iconfont icon-youjiantou"></i></span></div>';
            str+='<div class="conIntBox sunNum"><span class="txt">总质检数量：</span><span class="num">'+localStorage.qualityCountTotal+'</span></div>';
            str+='<div class="conIntBox noNum"><span class="txt">总不合格数量：</span><span class="num">'+localStorage.unqualityCountTotal+'</span></div>';

        }
        str+='<div class="qualityModeBut adoptBut active">提交</div>';
        layer.open({
            className: 'layui-select',
            zIndex:200,
            shadeClose:false,
            content: str
        });
    });
    //填写 质检数量时总质检数量动态改
    $('body').on('blur','#qualityCount',function () {
        if($(this).val()==''){
            $('.sunNum .num').html(localStorage.qualityCountTotal);
        }else{
            var sNum=parseInt(localStorage.qualityCountTotal)+parseInt($(this).val());
            localStorage.qualityCountTotalSun=sNum;
            $('.sunNum .num').html(sNum);
        }
    });
    //填写 次品时总不合格数量动态改
    $('body').on('blur','#unqualityCount',function () {
        if($(this).val()==''){
            $('.noNum .num').html(localStorage.unqualityCountTotal);
        }else{
            var nNum=parseInt(localStorage.unqualityCountTotal)+parseInt($(this).val());
            localStorage.unqualityCountTotalSun=parseInt($(this).val());
            $('.noNum .num').html(nNum);
        }

    });
    //完成质检-提交质检
    $('body').on('click','.adoptBut',function () {
        localStorage.qualityId=$('.startQualityBox').attr('quality-id');
        localStorage.qualityCount=$('#qualityCount').val();
        localStorage.unqualityCount=$('#unqualityCount').val();
        localStorage.batch=$('#batch').val();
        localStorage.img1='';
        localStorage.img2='';
        localStorage.img3='';
        localStorage.img4='';
        $('#testImages .img').each(function (index) {
            if(index==0){localStorage.img1=$(this).find('img').attr('data-url');}
            if(index==1){localStorage.img2=$(this).find('img').attr('data-url');}
            if(index==2){localStorage.img3=$(this).find('img').attr('data-url');}
            if(index==3){localStorage.img4=$(this).find('img').attr('data-url');}
        })
        if(partType==4){  //装备制造
            localStorage.qualType=2;  //1交班 2完成质检
           if(!$('.isQuality').hasClass('active')){
                $('.isQualityTop').addClass('active');
            }else{
               localStorage.qualityCount=1;
                if($('.isQuality.active').hasClass('no')){localStorage.result=2}else{localStorage.result=1}  //1 合格（通过） 2 不合格（异常）
                if(parseInt(localStorage.result)==2){
                    if (u.indexOf('iPhone') > -1) {   //苹果手机
                        location.href='qualityUnqual.html';
                    }else {
                        jsObj.openHyperLinkReference('qualityUnqual.html');
                    }
                }else{
                    var shiftObj={
                        qualityId:localStorage.qualityId,
                        qualityCount:localStorage.qualityCount,
                        result:localStorage.result,
                        type:localStorage.qualType,
                        img1:localStorage.img1,
                        img2:localStorage.img2,
                        img3:localStorage.img3,
                        img4:localStorage.img4,
                    }
                    metail(shiftObj)
                }
            }
        }else if(partType==3){  //金属
            localStorage.qualType=2;  //1交班 2完成质检
            if(localStorage.qualityCount==""){
                $('.qualityCountTop').addClass('active');
            }else if(localStorage.unqualityCount==""){
                $('.unqualityCountTop').addClass('active');
            }else if(localStorage.batch==""){
                $('.batchTop').addClass('active');
            }else if(!$('.isQuality').hasClass('active')){
                $('.isQualityTop').addClass('active');
            }else{
                if($('.isQuality.active').hasClass('no')){localStorage.result=2}else{localStorage.result=1}  //1 合格（通过） 2 不合格（异常）
                if(parseInt(localStorage.unqualityCount)>0){
                    if (u.indexOf('iPhone') > -1) {   //苹果手机
                        location.href='qualityUnqual.html';
                    }else {
                        jsObj.openHyperLinkReference('qualityUnqual.html');
                    }
                }else{
                    var shiftObj={
                        qualityId:localStorage.qualityId,
                        qualityCount:localStorage.qualityCount,
                        unqualityCount:localStorage.unqualityCount,
                        batch:localStorage.batch,
                        result:localStorage.result,
                        type:localStorage.qualType,
                        img1:localStorage.img1,
                        img2:localStorage.img2,
                        img3:localStorage.img3,
                        img4:localStorage.img4,
                    }
                    metail(shiftObj)
                }
            }
        }else{ //注塑
            localStorage.qualType=2;  //1交班 2完成质检
            if(localStorage.qualityCount==""){
                $('.qualityCountTop').addClass('active');
            }else if(localStorage.unqualityCount==""){
                $('.unqualityCountTop').addClass('active');
            }else if(localStorage.qualityType!=1&&localStorage.batch==""){   //只有 2 巡检 3终检
                $('.batchTop').addClass('active');
            }else if(!$('.isQuality').hasClass('active')){
                $('.isQualityTop').addClass('active');
            }else if(!$('.isAbnormal').hasClass('active')&&$('.isQuality.active').hasClass('no')){
                $('.isAbnormalTop').addClass('active');
            }else if($('#personLiable').val()==''&&$('.isQuality.active').hasClass('no')){
                $('.personLiable').addClass('active');
            }else{
                var unqunlityType='',personLiable='';
                if($('.isQuality.active').hasClass('no')){//1 合格（通过） 2 不合格（异常）
                    localStorage.result=2;
                    if($('.isAbnormal.active').hasClass('no')){  //5 yes（零件返工） 3 no（零件报废（废弃））
                        unqunlityType=3;
                    }else{
                        unqunlityType=5;
                    }
                    personLiable=$('#personLiable').attr('person-liable');
                }else{
                    localStorage.result=1
                }
                if(localStorage.qualityType==1){
                    localStorage.batch='';
                }
                var shiftObj={
                    qualityId:localStorage.qualityId,
                    qualityCount:localStorage.qualityCount,
                    unqualityCount:localStorage.unqualityCount,
                    batch:localStorage.batch,
                    result:localStorage.result,
                    unqunlityType:unqunlityType,
                    personLiable:personLiable,
                    type:localStorage.qualType,
                    img1:localStorage.img1,
                    img2:localStorage.img2,
                    img3:localStorage.img3,
                    img4:localStorage.img4,
                }
                plastic(shiftObj)
            }
        }
    });
    //质检完成 交班 完成质检（金属）
    function metail(Obj) {
        this.obj={
            qualityId:"",
            qualityCount:0,
            unqualityCount:0,
            batch:'',
            result:0,
            type:0,
            img1:'',
            img2:'',
            img3:'',
            img4:'',
            scrap:'[]',
            lose:'[]',
            rework:'[]',
        };

        var parameterObj=$.extend(this.obj,Obj);
        var url='/mes/zw/quality/handle/metail';
        var mdObj=md5Fun(appUserId,url,appToken);
        var parameter=Encrypt(JSON.stringify(parameterObj));
        console.log(parameter)
        console.log(Decrypt(parameter));
        $.ajax({
            type: "POST",
            timeout : 5000,
            url: webUrlCon+url,
            data:JSON.stringify(
                {"parameter":parameter}
            ),
            beforeSend: function(request) {
                request.setRequestHeader("Content-Type", "application/json");
                request.setRequestHeader("sequence", mdObj.sequence);
                request.setRequestHeader("nonceStr", mdObj.nonceStr);
                request.setRequestHeader("userId", appUserId);
                request.setRequestHeader("token",appToken);
                //xmlhttp.setRequestHeader("infName", url);
                //xmlhttp.setRequestHeader("osVersion", '');
                request.setRequestHeader("versionType", "1");
                request.setRequestHeader("osPlatform", mdObj.osPlatform);
                request.setRequestHeader("appVersion", mdObj.appVersion);
                request.setRequestHeader("sign", mdObj.sign);
            },
            success: function (data) {
                console.log(data);
                if(data.code==100){
                    layer.open({
                        content: '提交成功'
                        ,btn: '确定'
                        ,shadeClose:false
                        , yes: function(index){
                            layer.close(index)
                            //location.reload()
                            //location.href='testHistory.html';
                            if (u.indexOf('iPhone') > -1) {   //苹果手机
                                location.href='qualityHistory.html';
                            }else {
                                jsObj.openHyperLinkReference('qualityHistory.html');
                            }
                        }
                    });
                }else{
                    layer.open({
                        content: data.code+' '+data.message
                        ,btn: '确定'
                    });
                }
            },
            error: function(e) {
                layer.open({
                    content: '无法请求服务器，请稍后再试！'
                    ,btn: '确定'
                });
            }
        });
    }
    //质检完成 交班 完成质检（注塑）
    function plastic(Obj) {
        this.obj={
            qualityId:"",
            qualityCount:0,
            unqualityCount:0,
            batch:'',
            result:0,
            unqunlityType:0,
            personLiable:0,
            type:0,
            img1:'',
            img2:'',
            img3:'',
            img4:'',
        };
        var parameterObj=$.extend(this.obj,Obj);
        var url='/mes/zw/quality/handle/plastic';
        var mdObj=md5Fun(appUserId,url,appToken);
        var parameter=Encrypt(JSON.stringify(parameterObj));
        console.log(parameter)
        console.log(Decrypt(parameter));
        $.ajax({
            type: "POST",
            timeout : 5000,
            url: webUrlCon+url,
            data:JSON.stringify(
                {"parameter":parameter}
            ),
            beforeSend: function(request) {
                request.setRequestHeader("Content-Type", "application/json");
                request.setRequestHeader("sequence", mdObj.sequence);
                request.setRequestHeader("nonceStr", mdObj.nonceStr);
                request.setRequestHeader("userId", appUserId);
                request.setRequestHeader("token",appToken);
                //xmlhttp.setRequestHeader("infName", url);
                //xmlhttp.setRequestHeader("osVersion", '');
                request.setRequestHeader("versionType", "1");
                request.setRequestHeader("osPlatform", mdObj.osPlatform);
                request.setRequestHeader("appVersion", mdObj.appVersion);
                request.setRequestHeader("sign", mdObj.sign);
            },
            success: function (data) {
                console.log(data);
                if(data.code==100){
                    layer.open({
                        content: '提交成功'
                        ,btn: '确定'
                        ,shadeClose:false
                        , yes: function(index){
                            layer.close(index)
                            //location.reload()
                            //location.href='testHistory.html';
                            if (u.indexOf('iPhone') > -1) {   //苹果手机
                                location.href='qualityHistory.html';
                            }else {
                                jsObj.openHyperLinkReference('qualityHistory.html');
                            }
                        }
                    });
                }else{
                    layer.open({
                        content: data.code+' '+data.message
                        ,btn: '确定'
                    });
                }
            },
            error: function(e) {
                layer.open({
                    content: '无法请求服务器，请稍后再试！'
                    ,btn: '确定'
                });
            }
        });
    }



    /* 上传图片=============================== */
    /*$('.main').on('change','.photoInput',function () {
        if($(this).val()!=''){
            $('.loading').css('z-index','5');
        }
        var _this = this;
        var file = _this.files[0];
        var base64='';
        var base64Data='';
        var key ='img/h5/test2017_'+new Date().getTime()+'.JPG';
        lrz(file, {
            width: 1548
        })
            .then(function(rst) {
                base64=rst.base64;
                base64Data = base64.replace(/^data:image\/\w+;base64,/, "");
                base64Data = base64Data.replace(/\s/g,"+");
                client.put(key, new Buffer(base64Data,'base64')).then(function (result) {
                    console.log(result);
                    var imgBase='<div class="img">' +
                        '<i class="fileDel  iconfont icon-shanchu1"></i>' +
                        '<img data-url="'+result.name+'" src="'+base64+'">' +
                        '</div>';
                    $('.testImagesFile').before(imgBase)
                    if($('#testImages .img').length>3){
                        $('.testImagesFile').hide();
                    }else{
                        $('.testImagesFile').show();
                    }
                }).catch(function (err) {
                    console.log(err);
                });
                return rst;
            }).always(function () {
            // 不管是成功失败，都会执行
            $('.loading').css('z-index','1');
        });
    });*/
    //删除图片
    $('.main').on('click','.fileDel',function () {
        var _this=this;
        layer.open({
            content: '是否删除图片'
            ,btn: ['确定', '取消']
            ,yes: function(index){
                layer.close(index);
                $(_this).parent('div').remove();
                if($('#testImages .img').length>3){
                    $('.testImagesFile').hide();
                }else{
                    $('.testImagesFile').show();
                }
            }
        });
    });

    $('body').on('click','.personLiableSel',function () {
        $('#personName').trigger('click');
    });

});
